# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=onednn
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=2.1.3
pkgrel=1
pkgdesc='oneAPI Deep Neural Network Library (oneDNN) (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64')
url="https://github.com/oneapi-src/oneDNN"
license=('APACHE')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-doxygen" "${MINGW_PACKAGE_PREFIX}-ninja" "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://github.com/oneapi-src/oneDNN/archive/v${pkgver}.tar.gz")
sha256sums=('f652d6d25edf0073ace88700c2182abf2416fa562ced920bf899d887b202c025')

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -GNinja \
	-DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
	-DCMAKE_BUILD_TYPE=Release \
	-DDNNL_BUILD_EXAMPLES=OFF \
	-DDNNL_BUILD_TESTS=OFF \
    ../oneDNN-$pkgver
  
  ${MINGW_PREFIX}/bin/ninja $MAKEFLAGS
  ${MINGW_PREFIX}/bin/ninja doc
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  DESTDIR="$pkgdir" ${MINGW_PREFIX}/bin/ninja install
  cd "${srcdir}/${_realname}-${pkgver}"
  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
